package com.keepers.repair.helper;

import android.text.TextUtils;

import com.alibaba.fastjson.JSONObject;
import com.keepers.repair.model.RepairModel;
import com.keepers.repair.model.UserModel;
import com.keepers.repair.utils.SpUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * auth aboom
 * date 2018/10/22
 */
public class SpHelper {

    private static final String USER_INFO = "login_user_info";//登录信息

    private static final String GET_TASK_LIST_MODEL = "get_task_list_model";

    private static final String CURRENT_HTTP_HOST = "current_http_host";//app测试保存的域名

    private static final String CURRENT_HTTP_PORT = "current_http_port";//app测试保存的域名


    /**
     * 存储用户登录信息
     */
    public static void setLoginUserInfo(UserModel userModel) {
        String userModelStr = userModel == null ? "" : JSONObject.toJSONString(userModel);
        SpUtils.put(USER_INFO, userModelStr);
    }

    /**
     * 获取用户登录信息
     */
    public static UserModel getLoginUserInfo() {
        String user = SpUtils.getString(USER_INFO);
        UserModel userModel = null;
        if (!TextUtils.isEmpty(user)) {
            userModel = JSONObject.parseObject(user, UserModel.class);
        }
        return userModel;
    }

    /**
     * 任务信息
     */
    public static void setRepairModels(List<RepairModel> listModel) {
        String toJSONString = JSONObject.toJSONString(listModel);
        SpUtils.put(GET_TASK_LIST_MODEL, toJSONString);
    }

    public static List<RepairModel> getRepairModels() {
        List<RepairModel> listModels = new ArrayList<>();
        String string = SpUtils.getString(GET_TASK_LIST_MODEL);
        if (!TextUtils.isEmpty(string)) {
            listModels = JSONObject.parseArray(string, RepairModel.class);
        }
        return listModels;
    }

    /**
     * 保存当前测试环境域名
     */
    public static void setCurrentHttpHost(String currentHost) {
        SpUtils.put(CURRENT_HTTP_HOST, currentHost);
    }

    /**
     * 获取当前测试环境域名
     */
    public static String getCurrentHttpHost() {
        return SpUtils.getString(CURRENT_HTTP_HOST, "");
    }


    /**
     * 保存当前测试环境域名
     */
    public static void setCurrentHttpPort(int currentHost) {
        SpUtils.put(CURRENT_HTTP_PORT, currentHost);
    }

    /**
     * 获取当前测试环境域名
     */
    public static int getCurrentHttpPort() {
        return SpUtils.getInteger(CURRENT_HTTP_PORT);
    }

}
